﻿using JetBrains.Annotations;
using Orchard.Data;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement;
using Orchard.Caching;
using So.ImageResizer.Models;

namespace So.ImageResizer.Handlers {
    [UsedImplicitly]
    public class ImageResizerSettingsPartHandler : ContentHandler {

        private readonly ISignals _signals;
        public ImageResizerSettingsPartHandler(IRepository<ImageResizerSettingsPartRecord> repository, ISignals signals) {
            _signals = signals;
            Filters.Add(new ActivatingFilter<ImageResizerSettingsPart>("Site"));
            Filters.Add(StorageFilter.For(repository));
        }

        // private static string 

        protected override void Published(PublishContentContext context)
        {
            var part = context.ContentItem.As<ImageResizerSettingsPart>();
            if (part != null)
            {
                _signals.Trigger("ImageResizerSettingsPartChanged");
            }
            base.Published(context);
        }
    }
}